package HDAPI.examples;
import java.io.*;
import java.util.Enumeration;
import java.util.HashMap;

import javax.servlet.*;
import javax.servlet.http.*;

import HDAPI.*;

public class DetectExample3 extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
    	Utility.initHDAPISettings(this.getServletContext());
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

		HDBase hd = new HDBase();

		if ("NokiaN95".equals(request.getParameter("mobile"))) {
			hd.setDetectVar("user-agent", "Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaN95/12.0.013; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413");
		} else {
			hd.detectInit(Utility.getRequestHeaders(request), request.getRemoteAddr(), request.getRequestURL().toString());
		}

		if(hd.detectAll()){
			//redirect to a mobile version
			out.println("Mobile request detected");
			java.awt.Rectangle rect = hd.getDeviceResolution();
			out.println("Device resolution: " + rect.getWidth() +  " x " + rect.getHeight() + " <br/>");

			out.println("Click to call string: " + hd.getDeviceClickToCall() + " <br/>");
			out.println("Send SMS String: " + hd.getDeviceSendSms() + " <br/>");

		}else{
			//do nothing or regular version
			out.println("Normal request detected");
		}
		Utility.dumpError(hd, out);
    }

}